﻿#ifndef _ENEMY_H_
#define _ENEMY_H_
#include "ui/CocosGUI.h"
#include "cocos2d.h"
#include "cocostudio/CocoStudio.h"
enum EnemySpeed {slow = 15, Normal = 30, Fast = 120};
//enmu EnemyScale {Nromal = }
enum EnemyType{ CommonVirus, DeceleratingVirus, RegenerativeVirus};
enum EnemyLevel{ Level_1 = 1,Level_2, Level_3, Level_4, Level_5, Level_6};
class Enemy : public cocos2d::ui::Widget {
public:
	Enemy(EnemyType enemyType, EnemyLevel enemyLevel);
	static Enemy* create(EnemyType enemyType = CommonVirus, EnemyLevel enemyLevel = Level_1);
	bool init();
	void initActDir();//初始化运动方向
	void initEnemy();//初始化病毒
	void initCsbNode();//初始化csb节点
	void update(float dt);
	void slowTimeUpdate(float dt);
	void testUpdate(float dt);
	void runAct();//运行病毒动画
	void playEnemyDieAction();//播放病毒死亡动画
	void setEnemyPos(cocos2d::Vec2 pos) {
		enemyPos = pos;
	}
	void setEnemySpeed(EnemySpeed speed) {
		moveSpeed = speed;
	}
	cocos2d::Vec2 getEnemyInitPos() const {
		return enemyPos;
	}
	cocos2d::Vec2 getEnemyPos()const{
		return enemyCurrentPos;
	}
	cocos2d::Size getEnemySize() const {
		return enemySize;
	}
	void setLive(bool isLive){//设置病毒是否存活
		this->live = isLive;
	}
	bool getLive() const {
		return live;
	}
	int getCoin() const {
		return provideCoin;
	}
	EnemyType getEnemyType()const {
		return enemyType;
	}	
	EnemyLevel getEnemyLevel()const {
		return enemyLevel;
	}
	void hurt(int atk);//病毒受攻击
	void die();//病毒死亡
	void initSpriteFrameCache();//缓存plist文件
	cocos2d::Rect getEnemyRect();//返回自己的Rect
	void slowSpeed() {
		slowTime = 1;
	}
private:
	cocos2d::Node* root;
	int hp;//病毒的血量
	int enemy_size;//病毒的面积大小
	int moveSpeed;//病毒移动速度
	int slowTime;
	bool live;//是否生存
	int provideCoin;
	float scaleLevel[6] = {0.6, 0.7, 0.8, 0.9, 1.0, 1.1};
	EnemyType enemyType;//病毒类型
	EnemyLevel enemyLevel;//病毒等级
	cocos2d::ui::TextAtlas* hp_text;
	cocos2d::Sprite* enemyBody;
	cocos2d::Sprite* enemyDie;
	cocos2d::Size enemySize;
	cocos2d::Size size;
	cocos2d::Vec2 enemyPos;
	cocos2d::Vec2 enemyCurrentPos;
	cocos2d::Vec2 dir;
	cocos2d::SpriteFrameCache* enemySpriteCache;
};
#endif // !_ENEMY_H_


